//
//  ZLScreenExtension.swift
//  ZLExtension
//
//  Created by KDWL on 2023/1/9.
//

import Foundation

//MARK: 尺寸相关
public extension UIScreen {
    /// 屏幕宽度
    class func zl_width() -> CGFloat {
        return UIScreen.main.bounds.size.width
    }
    /// 屏幕高度
    class func zl_height() -> CGFloat {
        return UIScreen.main.bounds.size.height
    }
    /// 顶部安全区高度
    class func zl_safeTop() -> CGFloat {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return 0 }
            guard let window = windowScene.windows.first else { return 0 }
            return window.safeAreaInsets.top
        } else if #available(iOS 11.0, *) {
            guard let window = UIApplication.shared.windows.first else { return 0 }
            return window.safeAreaInsets.top
        }
        return 0
    }
    /// 底部安全区高度
    class func zl_safeBottom() -> CGFloat {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return 0 }
            guard let window = windowScene.windows.first else { return 0 }
            return window.safeAreaInsets.bottom
        } else if #available(iOS 11.0, *) {
            guard let window = UIApplication.shared.windows.first else { return 0 }
            return window.safeAreaInsets.bottom
        }
        return 0
    }
    /// 顶部状态栏高度（包括安全区）
    class func zl_statusBarHeight() -> CGFloat {
        var statusBarHeight: CGFloat = 0
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return 0 }
            guard let statusBarManager = windowScene.statusBarManager else { return 0 }
            statusBarHeight = statusBarManager.statusBarFrame.height
        } else {
            statusBarHeight = UIApplication.shared.statusBarFrame.height
        }
        return statusBarHeight
    }
    /// 导航栏高度
    class func zl_navigationBarHeight() -> CGFloat {
        return 44.0
    }
    /// 状态栏+导航栏的高度
    class func zl_navigationFullHeight() -> CGFloat {
        return self.zl_statusBarHeight() + self.zl_navigationBarHeight()
    }
    /// 底部导航栏高度
    class func zl_tabBarHeight() -> CGFloat {
        return 49.0
    }
    /// 底部导航栏高度（包括安全区）
    class func zl_tabBarFullHeight() -> CGFloat {
        return self.zl_tabBarHeight() + self.zl_safeBottom()
    }
    /// 屏幕比例
    class func zl_scale() -> CGFloat {
        return UIScreen.main.scale
    }
}
